<script setup lang="ts">
import useUserStore from '@/store/user'
import { getUserInfo } from '@/common/api'

const userStore = useUserStore()
onLaunch(() => {
  console.log('App Launch')
  /* #ifdef H5*/
  getWxSignature()
  wxLogin()
  /* #endif*/
})
onShow(() => {
  console.log('App Show')
  if (userStore.token) getUserInfo()
})
onHide(() => {
  console.log('App Hide')
})

/* #ifdef H5*/
import { getWxSignature } from '@/common/wx'
import { loginByWx } from '@/common/api'
async function wxLogin() {
  if (location.href.includes('code')) {
    const url = new URL(location.href)
    const code = url.search.split('=')[1].split('&')[0]
    const res = await loginByWx(code)
    userStore.openid = res.data.openId
  }
}
/* #endif*/

</script>
<style lang="scss">
@import "./style/globe.scss";
@import "./style/iconfont.scss";
</style>
